package Test1;

interface Stack1{

    public Object pop();
    public void push(Object object);
    public Object peek();
    public void print();
    public int size();
    public void Reverse();
}
public class ArrayStack implements Stack1{
      Object[] a=new Object[20];
      int number=0;
      public ArrayStack(){

     }

    public Object pop() {
        if (number==0){
            System.out.println("The stack is empty!");
            return null;
        }
        number--;
        Object ob = a[number];
        a[number]=null;
        return ob;
    }

    @Override
    public void push(Object object) {
          if (number==a.length){
              System.out.println("The data of satck is full!");
              return;
          }
          a[number]=object+"";
          number++;
    }


    @Override
    public Object peek() {
          if(number==0){
              System.out.println("The stack does not have data!");
              return null;
          }
        return a[number-1];
    }

    @Override
    public void print(){
             for(int i=0;i<a.length;i++){
                 System.out.println("a["+i+"]=="+a[i]);
             }

    }

    @Override
    public int size() {
        return number;
    }

    public void Reverse(){
          int n=a.length-1;

          for(int i=0;i<= n;i++){
              if (i==n||i==n+1){
                  break;
              }else{
                  Object b= a[i];
                  a[i]=a[n];
                  a[n]=b;
                  n--;
              }
          }

    }
}